<template>
	<view class="container">
		<view class="head_icon">
			<image :src="icon" style="width: 100px;height: 100px;" mode=""></image>
		</view>
		<view class="">
			<uni-forms ref="form" :model='user' :rules="myrules">
				<uni-forms-item label="用户名" name="username">
					<uni-easyinput v-model="user.username" placeholder="请输入用户名" prefixIcon="person-filled" />
				</uni-forms-item>
				<uni-forms-item label="密码" name="password">
					<uni-easyinput v-model="user.password" placeholder="请输入密码" prefixIcon="locked" type="password" />
				</uni-forms-item>

				<uni-forms-item label="" name="">
					<button class="btn " type="primary" :plain="false" :loading="false" @click="login()">登录</button>
				</uni-forms-item>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				icon: '../../static/cat-7.png',
				user: {
					username: '',
					password: '',

				},
				myrules: {
					username: {
						rules: [{
							required: true,
							errorMessage: '请输入用户名'
						}, {

							minLength: 3,
							maxLength: 5,
							errorMessage: '姓名长度在{minLength} 到{this.username.maxLength} 个字符',

						}]
					},
					password: {
						rules: [{
								required: true,
								errorMessage: '密码输入有误',
							},
							{

								maxLength: 11,
								errorMessage: '你输入的密码不符合要求',
							}
						]
					}
				}
			
		}
	},

	methods: {
		login() {
			
		
			let result = this.$refs.form.validate()
			if (result == true) {
				
			}
			if (this.user.username === 'tom' && this.user.password === '123') {
				setTimeout(() => {
					uni.switchTab({
						url: '../my/my'
					})
					},1000)
				uni.showToast({
					title: '欢迎你' + this.user.username,
					duration: 1000
				});
			} else {
				uni.showToast({
					title: '用户名或密码错误',
					icon: 'none',
					duration: 1000
				});
			}
		}
	},
	}
</script>

<style>
	.container {

		display: flex;
		/*设置容器为弹性布局容器*/

		flex-direction: column;
		/*内部组件主轴从上到下排布*/

		align-items: center;
		/*内部组件交叉轴水平居中*/

		width: '100%';

		padding-top: 10%;
	}

	.head_icon {
		padding: 40px;
	}

	.btn {
		background-color: #007aff;
	}
</style>